using System;
using System.Collections;
using System.IO;
using System.Text;
using System.Threading;
using System.Timers;
using System.Windows.Forms;
public class VipUtil
{
	public HttpService httpService = new HttpService();
	public Hashtable hashtable = new Hashtable();
	public int sleeptime = 120000;
	public int onlinememnum;
	public int ordertask;
	public int orderdltask;
	public int usergroup;
	public int visits;
	public long user_id;
	public string user_name = "";
	public string user_key = "";
	public string login_url = "";
	public string softwarename = "";
	public string main_exe = "";
	public string version = "";
	public string feetype = "";
	public string expiredate = "";
	public string md5 = "";
	public bool login(string softwarename, string main_exe, string version)
	{
		this.softwarename = softwarename;
		this.main_exe = main_exe;
		this.version = version;
		LoginForm loginForm = new LoginForm(softwarename, version);
		loginForm.login_url = this.login_url;
		loginForm.ShowDialog();
		this.user_id = loginForm.user_id;
		this.user_key = loginForm.user_key;
		this.user_name = loginForm.user_name;
		this.feetype = loginForm.feetype;
		this.expiredate = loginForm.expiredate;
		return loginForm.login_status;
	}
	public bool login1(string softwarename, string main_exe, string version)
	{
		this.softwarename = softwarename;
		this.main_exe = main_exe;
		this.version = version;
		LoginForm2 loginForm = new LoginForm2(softwarename, version);
		loginForm.login_url = this.login_url;
		loginForm.int_0 = this.usergroup;
		loginForm.ShowDialog();
		this.user_id = loginForm.user_id;
		this.user_name = loginForm.user_name;
		this.feetype = loginForm.feetype;
		this.expiredate = loginForm.expiredate;
		return loginForm.login_status;
	}
	public void online()
	{
		while (true)
		{
			try
			{
				string value = "";
				string text = this.httpService.post(this.login_url, string.Concat(new object[]
				{
					"softwarename=",
					this.softwarename,
					"&type=heartbeat&version=",
					this.version,
					"&user=",
					this.user_name,
					"&usergroup=",
					this.usergroup,
					"&loginid=",
					this.user_id,
					"&md5=",
					this.md5
				}));
				if (text.StartsWith("result="))
				{
					string[] array = text.Split(new char[]
					{
						'&'
					});
					for (int i = 0; i < array.Length; i++)
					{
						string text2 = array[i];
						string[] array2 = text2.Split(new char[]
						{
							'='
						});
						if (this.hashtable.ContainsKey(array2[0]))
						{
							this.hashtable[array2[0]] = array2[1];
						}
						else
						{
							this.hashtable.Add(array2[0], array2[1]);
						}
					}
					value = this.hashtable["result"].ToString();
					try
					{
						this.onlinememnum = int.Parse(this.hashtable["onlinememnum"].ToString());
					}
					catch
					{
					}
					try
					{
						this.ordertask = int.Parse(this.hashtable["ordertask"].ToString());
					}
					catch
					{
					}
					try
					{
						this.orderdltask = int.Parse(this.hashtable["orderdltask"].ToString());
						goto IL_1BA;
					}
					catch
					{
						goto IL_1BA;
					}
				}
				value = text;
				IL_1BA:
				if ("ok".Equals(value))
				{
					this.visits = 0;
				}
				else
				{
					if ("expired".Equals(value))
					{
						System.Timers.Timer timer = new System.Timers.Timer();
						timer.Interval = 60000.0;
						timer.Elapsed += new ElapsedEventHandler(this.method_3);
						timer.Start();
						MessageBox.Show("软件已过期，请续费(软件在1分钟内退出)！");
						break;
					}
					if ("notmatch".Equals(value) || "notlogined".Equals(value))
					{
						Random random = new Random();
						System.Timers.Timer timer = new System.Timers.Timer();
						timer.Interval = (double)random.Next(180000);
						timer.Elapsed += new ElapsedEventHandler(this.method_4);
						timer.Start();
						MessageBox.Show("登录异常！");
						break;
					}
					if ("error".Equals(value))
					{
						this.visits++;
						if (this.visits > 3)
						{
							Random random = new Random();
							System.Timers.Timer timer = new System.Timers.Timer();
							timer.Interval = (double)random.Next(60000);
							timer.Elapsed += new ElapsedEventHandler(this.method_3);
							timer.Start();
							MessageBox.Show("貌似发生点问题，请重新登录！！");
							break;
						}
					}
				}
			}
			catch
			{
			}
			Thread.Sleep(this.sleeptime);
		}
	}
	public void method_3(object sender, ElapsedEventArgs e)
	{
		Environment.Exit(Environment.ExitCode);
	}
	public void method_4(object sender, ElapsedEventArgs e)
	{
		string currentDirectory = Directory.GetCurrentDirectory();
		FileStream fileStream = new FileStream(currentDirectory + "\\config\\update.cmd", FileMode.Create);
		StreamWriter streamWriter = new StreamWriter(fileStream, Encoding.GetEncoding("GB2312"));
		streamWriter.WriteLine("taskkill /f /im " + this.main_exe);
		streamWriter.WriteLine(string.Concat(new string[]
		{
			"del \"",
			currentDirectory,
			"\\",
			this.main_exe,
			"\""
		}));
		streamWriter.WriteLine("del \"" + currentDirectory + "\\common.dll\"");
		streamWriter.WriteLine("ping -n 1 127.1>nul");
		streamWriter.WriteLine("exit");
		streamWriter.Flush();
		streamWriter.Close();
		streamWriter.Dispose();
		fileStream.Close();
		fileStream.Dispose();
		Environment.Exit(Environment.ExitCode);
	}
	public void login()
	{
		StringUtil.login(this.httpService, this.login_url, string.Concat(new object[]
		{
			"softwarename=",
			this.softwarename,
			"&type=logout&user=",
			this.user_name,
			"&loginid=",
			this.user_id
		}));
	}
}
